package ar.edu.itba.pod.legajo47573;


import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.List;

import ar.edu.itba.event.RemoteEventDispatcher;
import ar.edu.itba.node.Node;
import ar.edu.itba.node.NodeInformation;
import ar.edu.itba.node.api.ClusterAdministration;
import ar.edu.itba.pod.agent.runner.Agent;
import ar.edu.itba.pod.agent.runner.Simulation;
import ar.edu.itba.pod.multithread.EventDispatcher;
import ar.edu.itba.pod.multithread.LocalSimulation;
import ar.edu.itba.pod.multithread.MultiThreadEventDispatcher;
import ar.edu.itba.pod.time.TimeMapper;

public class MyNode {

	NodeInformation info;
	ClusterAdministration cluster;
	/*Adentro tiene los eventos locales y los agentes*/
	//EventDispatcher localEvents = new MultiThreadEventDispatcher();
	RemoteEventDispatcher remoteDispatcher;
	Simulation simulation;
	
	public MyNode(NodeInformation info/*, TimeMapper timeMapper*/){
		this.info = info;
		//this.simulation = new LocalSimulation(timeMapper);
		try {
			this.cluster = new ClusterAdministrationImpl(this);
			//this.remoteDispatcher = new RemoteEventDispatcherImpl(this);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Simulation getSimulation(){
		return simulation;
	}
	
	public RemoteEventDispatcher getRemoteDispatcher(){
		return remoteDispatcher;
	}
	
	public ClusterAdministration getCluster(){
		return cluster;
	}
	
	public NodeInformation getInfo(){
		return info;
	}
	
	public void createRegistry(){
		
	}
//	public void addAgent(Agent agent){
//		agents.add(agent);
//	}
//	
//	public void deleteAgent(Agent agent){
//		agents.remove(agent);
//	}
	
//	public static void main(String[] args) {
//		//localhost 1099 first
//		boolean first = false;
//		System.out.println(args[0]);
//		System.out.println(args[1]);
//		System.out.println(args[2]);
//		NodeInformation info = new NodeInformation(args[0], Integer.valueOf(args[1]), args[2]);
//		if(args[2].equals("first"))
//			first = true;
//		System.out.println(first);
//		MyNode node = new MyNode(info, first);
//		if (node.isFirst()) {
//			System.out.println("entre!");
//			try {
//				Registry registry = LocateRegistry.createRegistry(1099);
//				registry.bind(Node.CLUSTER_COMUNICATION, node.getCluster());
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		else{
//			try {
//				Registry registry = LocateRegistry.getRegistry("10.6.0.172",1500);
//				//Registry registry2 = LocateRegistry.createRegistry(1098);
//				//registry2.bind(Node.CLUSTER_COMUNICATION, node.getCluster());
//				ClusterAdministration stub = (ClusterAdministration)registry.lookup(Node.CLUSTER_COMUNICATION);
//				stub.getGroupId();
//				//stub.addNewNode(node.getInfo());
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}	
//		}
//	}

}
